package com.tj.collection.db.dao.impl;
import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.common.utils.CollectionUtils;
import com.google.common.collect.Maps;
import com.tj.collection.db.dao.RptModelLikeDao;
import com.tj.collection.db.entity.RptModelLikeEntity;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* User: linqu
* Date: 2023-11-29
* Time: 20:39:35.333
*/

@Repository
public class RptModelLikeDaoImpl extends AbstractBaseMapper<RptModelLikeEntity> implements RptModelLikeDao {

    @Override
    public Map<String, RptModelLikeEntity> listAllModelData() {
        final List<RptModelLikeEntity> listAllModelData = this.getSqlSession().selectList(this.getStatement("listAllModelData"));
        if (CollectionUtils.isEmpty(listAllModelData)) {
            return Maps.newHashMap();
        }
        return listAllModelData.parallelStream().collect(Collectors.toMap(RptModelLikeEntity::getModelUserCode, Function.identity()));
    }

    @Override
    public Map<String, RptModelLikeEntity> listModelData(List<String> modelUserCodes) {
        Map<String, Object> params = Maps.newHashMap();
        params.put("modelUserCodes", modelUserCodes);
        final List<RptModelLikeEntity> listAllModelData = this.getSqlSession().selectList(this.getStatement("listModelData"), params);
        if (CollectionUtils.isEmpty(listAllModelData)) {
            return Maps.newHashMap();
        }
        return listAllModelData.parallelStream().collect(Collectors.toMap(RptModelLikeEntity::getModelUserCode, Function.identity()));
    }
}